using System.Collections.Generic;
using System.ServiceModel.Syndication;

namespace aprogblog.Domain.Helpers {

    public static class EntryConverters {
        
        public static SyndicationItem ToItem(this Entry Entry) { return new SyndicationItem {
            Id = Entry.Id,
            Title = new TextSyndicationContent(Entry.Title),
            Summary = new TextSyndicationContent(Entry.Description)
        };}

        public static Entry ToEntry(this SyndicationItem Item) { return new Entry {
            Id = Item.Id,
            Title = Item.Title.Text,
            Description = Item.Description()
        };}

        public static string Description(this SyndicationItem Item) { return
            Item.Content != null ? ((TextSyndicationContent) Item.Content).Text :
            Item.Summary != null ? Item.Summary.Text :
            string.Empty          
        ;}

        public static List<Entry> ToEntries(this IEnumerable<SyndicationItem> Items) {
            var Entries = new List<Entry>();
            Items.ForEach(Item => Entries.Add(Item.ToEntry()));
            return Entries;
        }
    }
}